package com.cjy;
import java.io.DataInput;
import java.io.DataOutput;
 import java.io.IOException;
 import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;

public class FlowBean implements WritableComparable<FlowBean> {
    private String phoneNumber;//电话号码
    private long upFlow;//上行流量
   private long downFlow;//下行流量
   private long sumFlow;//总流量

    public String getPhoneNumber() {
         return phoneNumber;
        }
 public void setPhoneNumber(String phoneNumber) {
         this.phoneNumber = phoneNumber;
        }
 public long getUpFlow() {
      return upFlow;
    }
 public void setUpFlow(long upFlow) {
 this.upFlow = upFlow;
     }
 public long getDownFlow() {
        return downFlow;
         }
 public void setDownFlow(long downFlow) {
         this.downFlow = downFlow;
         }
 public long getSumFlow() {
         return sumFlow;
    }
public void setSumFlow(long sumFlow) {
         this.sumFlow = sumFlow;
}
//为了对象数据的初始化方便，加入一个带参的构造函数
 public FlowBean(String phoneNumber, long upFlow, long downFlow) {
         this.phoneNumber = phoneNumber;
         this.upFlow = upFlow;
         this.downFlow = downFlow;
        this.sumFlow = upFlow + downFlow;
        }
 //在反序列化时候，反射机制需要调用空参的构造函数，所以定义了一个空参的构造函数
         public FlowBean() {
         }

         //重写toString()方法
         @Override
        public String toString() {
         return "" + upFlow + "\t" + downFlow + "\t" + sumFlow + "";
         }


         //从数据流中反序列出对象的数据
         //从数据流中读取字段时必须和序列化的顺序保持一致
         public void readFields(DataInput in) throws IOException {
         phoneNumber = in.readUTF();
        upFlow = in.readLong();
        downFlow = in.readLong();
         sumFlow = in.readLong();

         }

         //将对象数据序列化到流中
         public void write(DataOutput out) throws IOException {
         out.writeUTF(phoneNumber);
         out.writeLong(upFlow);
         out.writeLong(downFlow);
         out.writeLong(sumFlow);

         }

         //流量比较的实现方法
         public int compareTo(FlowBean o) {

         //大就返回‐1，小于等于返回1，进行倒序排序
        return sumFlow > o.sumFlow ? -1 : 1;
         }


}